package com.shangrila.web.common.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

import com.shangrila.biz.open.utils.TaobaoMd5Sign;
import com.shangrila.web.common.SessionKeeper;

public class TaobaoCookieFilter implements Filter{

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
		
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		
		Cookie c1 = new Cookie(SessionKeeper.OPEN_TAOBAO_COOKIE_TIMESTAMP, TaobaoMd5Sign.timestamp);
		Cookie c2 = new Cookie(SessionKeeper.OPEN_TAOBAO_COOKIE_SIGN,TaobaoMd5Sign.getSign());
		Cookie c3 = new Cookie(SessionKeeper.OPEN_TAOBAO_COOKIE_ORIGNALSIGN, TaobaoMd5Sign.getOriginalSign());
		
		HttpServletResponse resp =(HttpServletResponse)response;
		resp.addCookie(c1);
		resp.addCookie(c2);
		resp.addCookie(c3);
		
		chain.doFilter(request, resp);
	}

	@Override
	public void destroy() {
		
	}

}
